package org.example.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.time.Duration;
import java.util.List;

/**
 * PanSou配置属性
 */
@Data
@Component
@ConfigurationProperties(prefix = "pansou")
public class PanSouProperties implements org.example.domain.config.PanSouProperties {

    /**
     * 默认TG频道列表
     */
    private List<String> defaultChannels = List.of("tgsearchers3");

    /**
     * 默认并发数
     */
    private int defaultConcurrency = 20;

    /**
     * 服务端口
     */
    private int port = 8888;

    /**
     * 代理配置
     */
    private ProxyProperties proxy = new ProxyProperties();

    /**
     * 启用的插件列表
     */
    private List<String> enabledPlugins;

    /**
     * 缓存配置
     */
    private CacheProperties cache = new CacheProperties();

    /**
     * 异步插件配置
     */
    private AsyncProperties async = new AsyncProperties();

    /**
     * HTTP客户端配置
     */
    private HttpProperties http = new HttpProperties();

    /**
     * 代理配置
     */
    @Data
    public static class ProxyProperties {
        private boolean enabled = false;
        private String url;
        private String type = "socks5";
    }

    /**
     * 缓存配置
     */
    @Data
    public static class CacheProperties implements org.example.domain.config.PanSouProperties.CacheConfig {
        private boolean enabled = true;
        private Duration ttl = Duration.ofMinutes(60);
        private int maxSize = 10000;
        private String path = "./cache";
        private int shardCount = 8;
        private String writeStrategy = "hybrid";
        private boolean compressionEnabled = false;
        private int minSizeToCompress = 1024;
    }

    /**
     * 异步配置
     */
    @Data
    public static class AsyncProperties implements org.example.domain.config.PanSouProperties.AsyncConfig {
        private boolean pluginEnabled = true;
        private Duration responseTimeout = Duration.ofSeconds(4);
        private Duration processingTimeout = Duration.ofSeconds(30);
        private int maxWorkers = 50;
        private int maxTasks = 200;
        private Duration cacheTtl = Duration.ofHours(1);
        private boolean logEnabled = true;
    }

    /**
     * HTTP配置
     */
    @Data
    public static class HttpProperties {
        private Duration readTimeout = Duration.ofSeconds(30);
        private Duration writeTimeout = Duration.ofSeconds(60);
        private Duration idleTimeout = Duration.ofSeconds(120);
        private int maxConnections = 1000;
        private int maxConnectionsPerHost = 200;
    }
}